package com.ctsi.security.app.permissiontree;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Path implements Serializable,Cloneable {
    private static final long serialVersionUID = -1434701310044035966L;

    private List<Item> item = new ArrayList<>();

    public List<Item> getItem() {
        return item;
    }

    public void setItem(List<Item> item) {
        this.item = item;
    }

    public Path() {
    }

    public void addItem(String id,String name){
        Item it = new Item();
        it.setTextContent(name);
        it.setId(id);
        item.add(it);
    }
    @Override
    public Object clone() throws CloneNotSupportedException {
        Path newPath = (Path) super.clone();
        List<Item> result = item.stream().map(item1 -> {
            Item m = null;
            try {
                 m = (Item) item1.clone();
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
            return m;
        }).collect(Collectors.toList());
        newPath.setItem(result);
        return newPath;
    }
}
